package com.loongtech.bi.manager.system;

import com.loongtech.bi.entity.POJO.Page;
import com.loongtech.bi.entity.system.EntityVipFightCoefficient;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Utils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.loongtech.bi.manager.system.SysProjectManager.projectIdNameMap;

@Service
public class VipFightCoefficientManager extends ManagerQueryCacheBase<EntityVipFightCoefficient> {

    /**
     *
     */
    private static final long serialVersionUID = 694490114987692777L;

    /**
     * 获取列表
     */
    public List<EntityVipFightCoefficient> queryList() {
        return findByQuery("from EntityVipFightCoefficient order by id");
    }

    /**
     * 查询用户(springmvc)
     */
    public Page<List<EntityVipFightCoefficient>> queryByCriteria(Integer curPage, Integer pageSize, EntityVipFightCoefficient e) {
        List<Object> param = new ArrayList<>();
        StringBuilder hql = new StringBuilder(" from EntityVipFightCoefficient e where 1=1 ");
        if (e.getVipLevel() != null) {
            hql.append(" and e.vipLevel = ?");
            param.add(e.getVipLevel());
        }
        if (e.getVipCoefficient() != null) {
            hql.append(" and e.vipCoefficient = ?");
            param.add(e.getVipCoefficient());
        }
        if (e.getGameId() != null) {
            hql.append(" and e.gameId like ?");
            param.add("%" + e.getGameId() + "%");
        }
        if (!Utils.isEmptyStr(e.getDescription())) {
            hql.append(" and e.description like ?");
            param.add("%" + e.getDescription() + "%");
        }
        hql.append(" order by e.gameId, vipLevel");
        Integer totalSize = countNum(hql.toString(), param.toArray());
        //数据
        List<EntityVipFightCoefficient> list = findByQuery((curPage - 1) * pageSize, pageSize, hql.toString(), param.toArray());
        if (list != null && list.size() > 0) {
            for (EntityVipFightCoefficient vipFightCoefficient : list) {
                String gameid = vipFightCoefficient.getGameId();
                for (Map.Entry<String, String> entry : projectIdNameMap.entrySet()) {
                    gameid = gameid.replace(entry.getKey() + ",", entry.getValue() + ",");
                }
                vipFightCoefficient.setGameName(gameid);
            }
        }
        return new Page<>(list, totalSize, curPage, pageSize);
    }
}
